{% extends "base.html" %}
{% block title %}| Boost - {{game.name}}{% endblock %}

{% block body %}

<center><h2>Boost  do jogo - {{ game.name }}</h2>
	<h3> {{ boost_db.name }} </h3>
	<h4> Criado por: <img class="meio" src="{{boost_db.creator.pic_url}}" height=20> <a class="meio" href="/rank/{{boost_db.creator}}">{{ boost_db.creator}} </a></h4>
</center>

<h1> Descricao </h1>
<div style="font-size:1.0em;color: #999; margin-left:20px">
{% autoescape off %}
<h4> {{ boost_db.desc }} </h4>
{% endautoescape %}
</div>

<h1> Regras </h1>
<div style="font-size:1.0em;color: #999; margin-left:20px">
{% autoescape off %}
{{ boost_db.rules }}
{% endautoescape %}
</div>
<h5>Obs.: Uma vez conquistando todos os trofeus, seu nome e automaticamente removido da lista, dando espaco para outros usuarios;</h5>


<br/>
<br/>

{% if boost_trophy_blck_db %}
<table align="center" height=35>
	<tr><th colspan=3><h3>Trofeus minimos</h3></th></tr>
	<tr height=35> 
		<th align="center"  > Trofeu </th>
		<th align="center"  > Detalhes </th>
		<th align="center"  > Tipo </th>
	</tr>
{% for b_trophy in boost_trophy_blck_db %}
	<tr> 
		<td>
			{% ifequal b_trophy.trophy.pic_url '0' %}
				<img class="meio" src="/media/no_image.png" width=54 height=54/>
			{% else %}
				{% ifequal b_trophy.trophy.pic_url 'hidden.png' %}
					<img class="meio" src="/media/hidden-lock.png" width=54 height=54/>
				{% else %}
					<img class="meio" src="/media/game/{{ b_trophy.trophy.game.psn_id }}/{{b_trophy.trophy.pic_url}}" width=54 height=54/>
				{% endifequal %}
			{% endifequal %}
		</td>
		<td width=300>
			{% autoescape off %}
			<b>{{ b_trophy.trophy.name }}</b> <br/>
			{{ b_trophy.trophy.desc }}</td>
			{% endautoescape %}
		</td>
		<td align="center">
			<img src="/media/{{ b_trophy.trophy.type }}.png" width=20 height=20 />
		</td>
	</tr>
{% endfor %}
</table>

{% endif %}

<table align="center" height=35>
	<tr><th colspan=3><h3>Trofeus a serem obtidos </h3></th></tr>
	<tr height=35> 
		<th align="center"  > Trofeu </th>
		<th align="center"  > Detalhes </th>
		<th align="center"  > Tipo </th>
	</tr>
{% for b_trophy in boost_trophy_earn_db %}
	<tr> 
		<td>
			{% ifequal b_trophy.trophy.pic_url '0' %}
				<img class="meio" src="/media/no_image.png" width=54 height=54/>
			{% else %}
				{% ifequal b_trophy.trophy.pic_url 'hidden.png' %}
					<img class="meio" src="/media/hidden-lock.png" width=54 height=54/>
				{% else %}
					<img class="meio" src="/media/game/{{ b_trophy.trophy.game.psn_id }}/{{b_trophy.trophy.pic_url}}" width=54 height=54/>
				{% endifequal %}
			{% endifequal %}
		</td>
		<td width=300>
			{% autoescape off %}
			<b>{{ b_trophy.trophy.name }}</b> <br/>
			{{ b_trophy.trophy.desc }}</td>
			{% endautoescape %}
		</td>
		<td align="center">
			<img src="/media/{{ b_trophy.trophy.type }}.png" width=20 height=20 />
		</td>
	</tr>
{% endfor %}
</table>

<br/>

<table align="center">
	<tr><th colspan=50>
		<h1> Lista de usuarios que precisam dos trofeus </h1>
		<h5> (Um trofeu colorido indica que o usuario ja conquistou o trofeu)</h5>
	</th></tr>
	<tr> <th>Usuario </th>
		{% for trophy in boost_trophy_earn_db %}
			<th> <img src="/media/game/{{game.psn_id}}/{{trophy.trophy.pic_url}}" width=50></th>
		{% endfor %}
	</tr>

		{% for user_need, trophy_have in users_need_db %}
			<tr> 
				<td><img src="{{user_need.pic_url}}" width=20> <a href="/rank/{{user_need.auth.username}}"> {{user_need.auth.username}} </a></td>
					{% for trophy_h in trophy_have %}
		 					<td align="center">{% if trophy_h %} <img src="/media/{{ trophy_h.trophy.type }}.png" width=20> {% else %} <img src="/media/hidden.png" width=20> {% endif %}</td>
					{% endfor %}
			</tr>
		{% endfor %}

	{% if users_done_db %}
	<tr><th colspan=50>
		<h1> Lista de usuarios que ja completaram </h1>
		{% for user_done, trophy_done in users_done_db %}
			<tr> 
				<td><img src="{{user_done.pic_url}}" width=20> <a href="/rank/{{user_done.auth.username}}"> {{user_done.auth.username}} </a></td>
					{% for trophy_h in trophy_done %}
		 					<td align="center">{% if trophy_h %} <img src="/media/{{ trophy_h.trophy.type }}.png" width=20> {% else %} <img src="/media/hidden.png" width=20> {% endif %}</td>
					{% endfor %}
			</tr>
		{% endfor %}
	{% endif %}
</table>

{% if boost_db.subscribe %}
<table>
	<tr> 
		<th>User </th>
		<th>Data</th>
	</tr>

	{% for boost_user in boost_user_db %}
		<tr>
			<td> {{boost_user.user.auth.username}} </td>
			<td> {{boost_user.date }}</td>
		</tr>
	{% endfor %}
</table>
{% endif %}

<br/>

{% ifequal user.auth.username 'fabriciols' %}
<center><h1> Controle de cadastro de Boost </h1>
{% if boost_db.subscribe %}
<br/><br/>
<form method="post" action=".">{% csrf_token %}
	{{ user_formset.management_form }}
	<table>
		  <tr> <th colspan=2> Boost - {{ game.name }} - User</th> </tr>
		  <tr> <th> User </th> <th> Apagar </th>
    {% for form in user_formset.forms %}
			<tr>
			{% for field in form.visible_fields %}
				<td>

				{% if forloop.first %}
					{% for hidden in form.hidden_fields %}
						{{ hidden }}
					{% endfor %}
				{% endif %}
				{{ field }} 
				</td>

			{% endfor %}
			</tr>

    {% endfor %}

	<tr><td colspan=2 align="center"> <input type="submit" value="Submit"></td></tr>
	</table>

</form>
{% endif %}

<br/><br/>

<form method="post" action=".">{% csrf_token %}
	<table>
		<tr> <th colspan=3> Boost - {{ game.name }} - Trophy</th> </tr>
		<tr> <td> Trophy </td> <td> Type </td> <td> Apagar </td> </tr>
		<tr>
		{{ trophy_formset.management_form }}
		   {% for form in trophy_formset.forms %}
				{% for field in form.visible_fields %}
					<td>

					{% if forloop.first %}
						{% for hidden in form.hidden_fields %}
						{{ hidden }}
					{% endfor %}
				{% endif %}

				{% ifequal field.label 'Trophy' %}
					<select name="{{field.html_name}}" id="{{field.html_name}}"> 
					<option value="" selected="selected">---------</option> 
					{% for trophy in trophy_db %}
						<option value="{{trophy.id}}" {% ifequal  form.initial.trophy trophy.id %} selected="selected" {% endifequal %}>{{trophy.name}}</option> 
					{% endfor %}
				{% else %}
				{{ field }}
				{% endifequal %}
				</td>
		{% endfor %}
		</tr>
   {% endfor %}
		<tr><td colspan=2 align="center"> <input type="submit" value="Submit"></td></tr>
	</table>
</form>

</center>
{% endifequal %}

<br/><br/>

{% endblock %}
